﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;

namespace Drag
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        private readonly ObservableCollection<SolidColorBrush> _brushes;
        public MainWindow()
        {
            DataContext = _brushes = new ObservableCollection<SolidColorBrush>(App.DemoColors.Select(c => c.ToBrush()));
            InitializeComponent();
        }
        private void listbox_Reorder(object sender, ReorderEventArgs args)
        {
            var reorderListBox = (ReorderListBox)args.OriginalSource;

            var draggingBrush = (SolidColorBrush)reorderListBox.ItemContainerGenerator.ItemFromContainer(args.ItemContainer);
            var toBrush = (SolidColorBrush)reorderListBox.ItemContainerGenerator.ItemFromContainer(args.ToContainer);

            _brushes.Move(_brushes.IndexOf(draggingBrush), _brushes.IndexOf(toBrush));
        }
    }
}
